package cn.sh.library.gmwx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.sh.library.gmwx.base.Constant;
import cn.sh.library.gmwx.bean.OrganizationSearchBean;
import cn.sh.library.gmwx.dto.Pager;
import cn.sh.library.gmwx.service.OrganizationService;
import cn.sh.library.gmwx.sparql.BaseinfoSparql;

@Controller
@RequestMapping("/orgrepo")
public class OrganizationController extends BaseController{
    @Resource
    private OrganizationService organizationService;
    @Resource
    private BaseinfoSparql baseinfoSparql;

    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public Map<String, Object> query(Model model, OrganizationSearchBean search, Pager pager){
        Map<String, Object> result = new HashMap<>();

        List<Map<String, String>> list = this.organizationService.list(search, pager);

        result.put("resultList", list);
        result.put("pager", pager);
        return result;
    }

    @ResponseBody
    @RequestMapping(value = "getTriples", method = RequestMethod.POST)
    public Map<String, Object> getTriples(Model model, String uri) {
        Map<String, Object> result = new HashMap<>();

        result.put("resultList", this.baseinfoSparql.getTriples(Constant.GRAPH_ORGANIZATION, uri));
        return result;
    }
}
